﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using sexhealth.console.service.post;
using sexhealth.console.service.activity.vo;
using com.pro2e.web.util.page;
using com.pro2e.web;

public partial class Activity : System.Web.UI.Page
{
    ActivityService activityService = new ActivityService();
    HttpHelper httpHelper = new HttpHelper();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSend_Click(object sender, ImageClickEventArgs e)
    {
        if (!ckbOption1_1.Checked && !ckbOption1_2.Checked && !ckbOption1_3.Checked)
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("請您至少選擇一項建議，謝謝。"), false);
        }
        else
        {
            AnswerVO answerVO = new AnswerVO();
            answerVO.ActivityId = AnswerVO.LatestActivityId;
            answerVO.AnswerType = AnswerType.None;
            answerVO.Option1_1 = ckbOption1_1.Checked;
            answerVO.Option1_2 = ckbOption1_2.Checked;
            answerVO.Option1_3 = ckbOption1_3.Checked;
            answerVO.CreatedIP = httpHelper.GetUserIp(Context);

            activityService.CreateAnswer(answerVO);

            ClearUI();

            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("謝謝您協助給予建議。"), false);
        }
    }

    private void ClearUI()
    {
        ckbOption1_1.Checked = false;
        ckbOption1_2.Checked = false;
        ckbOption1_3.Checked = false;
    }
}